Skip to content

Conversation

lcian
Copy link
Member

@lcian lcian commented Sep 19, 2025

Description

In #887 we added some attributes that are attached by default on all spans to surface more metadata.
We have an option on the tracing layer called enable_span_attributes that, when emitting an error/log out of a tracing event, attaches all the attributes of each span in the currently active span hierarchy to the error/log.

This results in a lot of noise, as you will see those attributes for every span that is currently active, which doesn't provide much value when looking at an error/log.
See this example with a log:
Screenshot 2025-09-22 at 12 56 37

With this change, we'll only propagate user-provided attributes to the error/log, skipping those we set by default on the spans.
When looking at the trace in Sentry, you'll still be able to see those on the corresponding span, as it provides valuable information.

Issues

Close #895
Close RUST-104

#skip-changelog because this fixes a bug for something that wasn't released

@lcian lcian changed the title changelog fix(tracing): skip default span attributes when propagating to event Sep 19, 2025
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.44%. Comparing base (75a8c03) to head (3583b7a).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #904      +/-   ##
==========================================
- Coverage   73.44%   73.44%   -0.01%     
==========================================
  Files          64       64              
  Lines        7502     7513      +11     
==========================================
+ Hits         5510     5518       +8     
- Misses       1992     1995       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

linear bot commented Sep 22, 2025

@lcian lcian marked this pull request as ready for review September 22, 2025 11:28
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes overall look reasonable, but could you please link to something in the develop docs for SDKs which says that this is the desired SDK behavior? Or, is this behavior which the SDKs are free to define their desired behavior?

match &span_data.sentry_span {
TransactionOrSpan::Span(span) => {
for (key, value) in span.data().iter() {
if is_sentry_span_attribute(key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that a user would set a Sentry span attribute manually, and would we want to keep that attribute in that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: also I would suggest using a .filter on the iterator, rather than the if block with a continue. Imo iterator chains tend to be more readable than branching via if statements

Copy link
Member Author

@lcian lcian Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlikely, but in theory it's possible that you could want to override them yeah.

@lcian
Copy link
Member Author

lcian commented Sep 22, 2025

This behavior (enable_span_attributes) is unique to the tracing layer, it doesn't apply to any other integration or SDK, so there's no standard/spec for this.
If we were to propose it, I don't think it would be implemented.
But in this SDK it's already here because someone found it useful, and honestly I can see the value in it.
So I would just keep it there and with this patch we ensure those fields don't become too noisy for no benefit.

Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, this looks good to me! Would still swap to .filter, but this looks fine to me already

@lcian lcian merged commit 75aff83 into master Sep 23, 2025
32 of 36 checks passed
@lcian lcian deleted the lcian/skip-default-attributes branch September 23, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix tracing span attributes in logs
2 participants